package com.liang.service.impl;

import com.liang.dao.UserActionMapper;
import com.liang.pojo.UserAction;
import com.liang.service.UserActionService;
import com.liang.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;

public class UserActionServiceImpl implements UserActionService {

    static SqlSession sqlSession= null;

    //用户行为数据插入
    public int addUserAction(int userId, int movieId, float score) {
        sqlSession= MybatisUtils.getSqlSessionAuto();
        UserActionMapper mapper = sqlSession.getMapper(UserActionMapper.class);
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("user_id",userId);
        map.put("movie_id",movieId);
        map.put("score",score);
        int i = mapper.addUserAction(map);
        sqlSession.close();
        return i;
    }

    public List<UserAction> getUserActionListById(int id) {
        sqlSession = MybatisUtils.getSqlSessionAuto();
        UserActionMapper mapper = sqlSession.getMapper(UserActionMapper.class);
        List<UserAction> listById = mapper.getUserActionListById(id);
        sqlSession.close();
        return listById;
    }

    public int[] getUserId() {
        sqlSession = MybatisUtils.getSqlSessionAuto();
        int[] userId = sqlSession.getMapper(UserActionMapper.class).getUserId();
        sqlSession.close();
        return userId;
    }

    public int[] getMovieIdById(int userId) {
        sqlSession = MybatisUtils.getSqlSessionAuto();
        int[] movieId = sqlSession.getMapper(UserActionMapper.class).getMovieIdById(userId);
        sqlSession.close();
        return movieId;
    }
}
